package ink.tiptop.learn.controller;

import ink.tiptop.learn.pojo.CommonResult;
import ink.tiptop.learn.pojo.dto.orderInfo.*;
import ink.tiptop.learn.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (OrderInfo)表控制层
 *
 * @author zjf
 * @since 2020-08-14 20:51:45
 */
@RestController
@RequestMapping("orderInfo")
@Slf4j
public class OrderInfoController {
    /**
     * 服务对象
     */
    @Resource
    private OrderInfoService orderInfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public CommonResult selectOne(Integer id) {
        return this.orderInfoService.queryById(id);
    }

    /**
     * 通过实体类查询列表数据
     *
     * @param request 实例对象
     * @return 单条数据
     */
    @PostMapping("list")
    @ResponseBody
    public CommonResult list(@RequestBody @Valid QueryOrderInfoDto request) {
        log.info("查询列表信息,入参:{}", request.toString());
        return this.orderInfoService.list(request);
    }

    @PostMapping("update")
    @ResponseBody
    public CommonResult update(@RequestBody @Valid UpdateOrderInfoDto request) {
        log.info("更新单一信息,入参:{}", request.toString());
        return this.orderInfoService.update(request);
    }

    @PostMapping("delete")
    @ResponseBody
    public CommonResult delete(@RequestBody @Valid DeleteOrderInfoDto request) {
        log.info("批量删除信息,入参:{}", request.toString());
        return this.orderInfoService.delete(request);
    }


    /**
     * @param request 主键
     * @return 单条数据
     */
    @PostMapping("add")
    @ResponseBody
    public CommonResult add(@RequestBody @Valid AddOrderInfoDto request) {
        log.info("添加信息,入参:{}", request.toString());
        return this.orderInfoService.add(request);
    }

    /**
     * @param request 主键
     * @return 单条数据
     */
    @PostMapping("userOrder")
    @ResponseBody
    public CommonResult userOrder(@RequestBody @Valid CustomerOrderInfoDto request) {
        log.info("自定义查询,入参:{}", request.toString());
        return this.orderInfoService.userOrder(request);
    }


}